<!DOCTYPE html>
<!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns="http://www.w3.org/1999/html"
      xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>员工管理页面</title>
    <!-- Bootstrap core CSS -->
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet">
    <link th:href="@{/css/bootstrap-grid.css}" rel="stylesheet">
    <link th:href="@{/css/bootstrap-reboot.css}" rel="stylesheet">
    <link th:href="@{/css/bootstrap-datetimepicker.min.css}" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/limonte-sweetalert2/6.6.2/sweetalert2.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link th:href="@{/css/dashboard.css}" rel="stylesheet">
    <style type="text/css">
        /* Chart.js */

        @-webkit-keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        @keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        .chartjs-render-monitor {
            -webkit-animation: chartjs-render-animation 0.001s;
            animation: chartjs-render-animation 0.001s;
        }

        #searchButton{
            margin-left: 20px;
            width: 100px;
            padding: 0 20px;
            height: 30px;
            border: 1px solid #7ba92c;
            border-radius: 4px;
            color: #fff;
            font-weight: bold;
            background:#87c212;
        }
    </style>
</head>

<body>
<!--顶部导航栏-->
<div th:replace="~{commons/commons::topbar}"></div>

<div class="container-fluid">
    <div class="row">
        <!--将侧边栏抽取为公共部分-->
        <div th:replace="~{commons/commons::sidebar(active='user/list.html')}"></div>

        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <!--显示分页信息-->
            <div class="modal-footer pager no-margin-top" style="justify-content: space-between;">
                <div class="col-md-3">
                    一共 [[${pageInfo.total}]] 条记录 当前第 [[${pageInfo.pageNum}]] / [[${pageInfo.pages}]] 页
                </div>
                <!--pagination-lg pull-right no-margin-->
                <ul class="pagination">
                    <li class="page-item" th:if="${pageInfo.hasPreviousPage}">
                        <a class="page-link" th:href="'/zjn/user/list?pageNum=1'">首页</a>
                    </li>

                    <li class="page-item prev" th:if="${pageInfo.hasPreviousPage}">
                        <a class="page-link" th:href="'/zjn/user/list?pageNum='+${pageInfo.prePage}">
                            <i class="ace-icon fa fa-angle-double-left"></i>
                        </a>
                    </li>
                    <!--遍历条数-->
                    <li class="page-item" th:each="nav:${pageInfo.navigatepageNums}">
                        <a class="page-link" th:href="'/zjn/user/list?pageNum='+${nav}" th:text="${nav}" th:if="${nav != pageInfo.pageNum}"></a>
                        <a class="page-link" style="font-weight: bold;background: rgba(110,171,215,0.99);" th:if="${nav == pageInfo.pageNum}" th:text="${nav}" ></a>
                    </li>

                    <li class="page-item next" th:if="${pageInfo.hasNextPage}">
                        <a class="page-link" th:href="'/zjn/user/list?pageNum='+${pageInfo.nextPage}">
                            <i class="ace-icon fa fa-angle-double-right"></i>
                        </a>
                    </li>

                    <li class="page-item">
                        <a class="page-link" th:href="'/zjn/user/list?pageNum='+${pageInfo.pages}">尾页</a>
                    </li>
                </ul>
            </div>

            <form th:action="@{/user/list}" method="get" class="form-control">
                <div class="input-group">
                    <div class="input-group-text col-sm-12">
                        <span class="input-group-addon">用户姓名：</span>
                        <input type="text" name="queryName" class="form-control col-sm-2" th:value="${queryName}">
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <span class="input-group-addon">用户权限：</span>
                        <select name="queryUserRole" id="queryUserRole" class="form-control col-sm-2" th:value="${queryUserRole}">
                            <option value="0">--请选择--</option>
                            <option th:each="userRole:${roleList}"
                                    th:value="${userRole.getId()}"
                                    th:text="${userRole.getRoleName()}"
                                    th:selected="${queryUserRole == userRole.getId()}">
                            </option>
                        </select>
                        <span class="col-sm-1"></span>
                        <button type="submit" class="" id="searchButton">查询</button>
                        <span class="col-sm-2"></span>
                        <span class="" style="float: right">
                            <a class="btn btn-sm btn-success"
                               th:href="@{/user/userAdd}">添加员工</a>
                        </span>
                    </div>
                </div>
            </form>

            <div class="table-responsive">
                <table class="table table-striped table-sm table-bordered" style="width: 100%">
                    <thead>
                    <tr>
                        <th class="text-center">编码</th>
                        <th class="text-center">姓名</th>
                        <th class="text-center">性别</th>
                        <th class="text-center">年龄</th>
                        <th class="text-center">电话</th>
                        <th class="text-center">职位</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="user:${pageInfo.getList()}">
                        <input type="hidden" class="userId" name="id" th:value="*{user.getId()}">
                        <td class="text-center" th:text="*{user.getUserCode()}"></td>
                        <td class="text-center" th:text="*{user.getUserName()}"></td>
                        <td class="text-center" th:text="*{user.getGender()}==2 ? '女':'男'"></td>
                        <td class="text-center" th:text="*{user.getAge()}"></td>
                        <td class="text-center" th:text="*{user.getPhone()}"></td>
                        <td class="text-center" th:text="*{user.getUserRoleName()}"></td>
                        <td class="text-center">
                            <a class="btn btn-sm btn-info" th:href="@{/user/userUpdate/{id}(id=${user.id})}">修改</a>
                            <a class="btn btn-sm btn-outline-secondary" th:href="@{/user/userView/{id}(id=${user.id})}">查看</a>
                            <a shiro:hasPermission="user:admin" class="btn btn-sm btn-danger del" th:attr="userId = ${user.id}">删除</a>
                            <!--th:href="@{/user/userDelete/{id}(id=${user.id})}" onclick="deleteId()"-->
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </main>
    </div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->

<script type="text/javascript" th:src="@{/js/jquery-3.2.1.min.js}"></script>
<script type="text/javascript" th:src="@{/js/popper.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-datetimepicker.js}"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/limonte-sweetalert2/6.6.2/sweetalert2.min.js"></script>

<!--删除按钮-->
<script type="text/javascript" th:inline="javascript">

    $('.del').on("click", function () {
        //获取当前标签对象
        var $tr =$(this).parent().parent();
        var code=$(this).parent().parent().find(".userId").val();
        swal({
            title: "确定删除吗？",
            text: "如果确定将不能恢复这条数据！",
            type: "warning",
            showCancelButton: true,
            confirmButtonText: "确定",
            cancelButtonText: "取消",   //修改cancel显示的
            showLoaderOnConfirm: true  //加载等待时间的显示页面
        }).then(function () {
            $.ajax({
                type: 'GET',
                url: '/zjn/user/userDelete',
                data: {'code': code},
                dataType: 'json',
                async: false,
                success: function (data) {  // 后端发字典过来 前端不需要你手动转 会自动帮你转换成js自定义对象
                    /*console.log(data.code);*/
                    if (data.code == "success") {
                        // 通过DOM操作 实时改变页面
                        // 将被点击的删除按钮所在的那一行直接从DOM树中删掉
                        $tr.remove();
                        swal(
                            '删除成功！',
                            '该条数据已被成功删除。',
                            'success'
                        ).then(function () {
                            window.location.reload()  //刷新页面
                        });
                    } else if (data.code == "error") {
                        swal('发生了未知的错误', '估计是有bug了', 'info');
                    }
                },
                error: function () {
                    swal("后台出错", "请重新执行该操作", "error");
                }
            });
        }, function(dismiss) {
            // dismiss的值可以是'cancel', 'overlay',
            // 'close', 'timer'
            if (dismiss === 'cancel') {
                swal(
                    '已取消！',
                    '你的数据是安全的:)',
                    'info'
                );
            }
        })
    });

</script>

<!-- Icons -->
<script type="text/javascript" th:src="@{/js/feather.min.js}"></script>
<script>
    feather.replace()
</script>

<!-- Graphs -->
<script type="text/javascript" th:src="@{/js/Chart.min.js}"></script>

<script>
    var ctx = document.getElementById("myChart");
    var myChart = new Chart(ctx, {
        type: 'line',
        data: {
            labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
            datasets: [{
                data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
                lineTension: 0,
                backgroundColor: 'transparent',
                borderColor: '#007bff',
                borderWidth: 4,
                pointBackgroundColor: '#007bff'
            }]
        },
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: false
                    }
                }]
            },
            legend: {
                display: false,
            }
        }
    });
</script>

</body>

</html>